//
//  MMMainViewController.m
//  zhihuDaily
//
//  Created by  陈聪 on 16/6/11.
//  Copyright © 2016年 cc. All rights reserved.
//

#import "MMMainViewController.h"
#import "SYTheme.h"
#import "MMHomeController.h"
#import "MMNavigationController.h"
#import "MMThemeController.h"
@interface MMMainViewController ()

@end

@implementation MMMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    White_StatusBar;
    // Do any additional setup after loading the view.
    [kNotificationCenter addObserver:self selector:@selector(openDrawer) name:OpenDrawer object:nil];
    [kNotificationCenter addObserver:self selector:@selector(closeDrawer) name:CloseDrawer object:nil];
    [kNotificationCenter addObserver:self selector:@selector(toggleDrawer) name:ToggleDrawer object:nil];
//    self.panFromEdge = NO;
//    self.fadeMenuView = NO;
//    self.parallaxEnabled = NO;
//    self.scaleBackgroundImageView = NO;
//    self.scaleContentView = NO;
//    self.scaleMenuView = NO;
//    self.contentViewInPortraitOffsetCenterX = 20;
    
    
}

-(void)dealloc{
    [kNotificationCenter removeObserver:self];
}


#pragma mark - 事件处理
- (void)openDrawer{
//    [self presentLeftMenuViewController];
    if (self.mainView.frame.origin.x >0) {
        [self closeDrawerWithAnimateDuration:0.3];
    }else{
        [self openDrawerWithAnimateDuration:0.3];
    }
    
}

- (void)closeDrawer{
//    [self hideMenuViewController];
    [self closeDrawerWithAnimateDuration:0.3];
}

- (void)toggleDrawer{
    
}
//让SYMainViewController成为SYLeftDrawerController的代理，当SYLeftDrawerController的tableview的cell被选择的时候，通知SYMainViewController修改CenterViewController
#pragma mark - SYLeftDrawerControllerDelegate
- (void)LeftDrawerController:(SYLeftDrawerController *)leftDrawerController menuButtonClicked:(SYTheme *)theme{
    if ([theme.name isEqualToString:@"首页"]) {
        MMNavigationController *nav =[[MMNavigationController alloc]initWithRootViewController:[[MMHomeController alloc]init]];
        [self setMyContentViewController:nav];
//        self.contentViewController =  nav;
//        nav.view.frame = CGRectMake(180, 0, MMScreenW, MMScreenH);
//        [self.mainView removeFromSuperview];
//        self.mainView  = nav.view;
//        [self.view addSubview:self.mainView];
//        MMLog(@"%@",NSStringFromCGRect(self.mainView.frame));
//        MMLog(@"%@",NSStringFromCGRect(nav.view.frame));
    }else{
        MMThemeController *themevc = [[MMThemeController alloc]init];
        themevc.theme = theme;
        MMNavigationController *nav =[[MMNavigationController alloc]initWithRootViewController:themevc];
        [self setMyContentViewController:nav];
//        MMLog(@"%@",NSStringFromCGRect(nav.view.frame));
//        nav.view.frame = CGRectMake(180, 0, MMScreenW, MMScreenH);
////        [self.mainView removeFromSuperview];
//        self.mainView  = nav.view;
//        [self.view addSubview:self.mainView];
//        MMLog(@"%@",NSStringFromCGRect(self.mainView.frame));
//        MMLog(@"%@",NSStringFromCGRect(nav.view.frame));
        
    }
    [self closeDrawer];
}

@end
